package com.hong.chapter1;

/**
 * Created by hong on 2018/5/27.
 * 线程和守护线程
 */
public class TryConcurrency {

    public static void main(String[] args) {
        Thread t = new Thread("READ-Thread"){
            @Override
            public void run(){
                println(Thread.currentThread().getName());
                readFromDataBase();
            }
        };

        t.start();
/*
        new Thread("WRITE-THREAD"){
            @Override
            public void run(){
                writeDataToFile();
            }
        }.start();*/


        /*Thread t1 = new Thread("ThreadOne"){
            @Override
            public void run(){
                for (int i=0;i<1000;i++){
                    println("Task ->"+i);
                }
            }
        };
        t1.start();

        for (int j = 0;j<100;j++){
            println("Task 2=>"+j);
        }*/


        /*for (int i = 0;i<100;i++){
            println("Task i=>"+i);
        }

        for (int j=0;j<100;j++){
            println("Task j=>"+j);
        }*/
        /*try {
            Thread.sleep(1000*300L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        readFromDataBase();
        writeDataToFile();*/
    }

    private static void readFromDataBase(){
        try {
            println("Begin read data from db.");
            Thread.sleep(1000 * 20L);
            println("Read data done and start handle it.");

        }catch (Exception e){
            e.printStackTrace();
        }

        println("The data handle finish and successfully.");
    }

    private static void writeDataToFile(){
        println("Begin write data from db.");
    }

    private  static  void println(String message){
        System.out.println(message);
    }

}
